home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE2 / PD / VINCE / !ViNCe / c / rfbproto < prev    next >
Text File  |  2002-07-04  |  17KB  |  666 lines

  1. /*
  2.  *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
  3.  *
  4.  *  This is free software; you can redistribute it and/or modify
  5.  *  it under the terms of the GNU General Public License as published by
  6.  *  the Free Software Foundation; either version 2 of the License, or
  7.  *  (at your option) any later version.
  8.  *
  9.  *  This software is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  *  GNU General Public License for more details.
  13.  *
  14.  *  You should have received a copy of the GNU General Public License
  15.  *  along with this software; if not, write to the Free Software
  16.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  17.  *  USA.
  18.  */
  19.  
  20. /*
  21.  * rfbproto.c - functions to deal with client side of RFB protocol.
  22.  */
  23.  
  24. #include <time.h>
  25.  
  26. #include "oslib/os.h"
  27. #include "oslib/socket.h"
  28.  
  29. #include "vncviewer.h"
  30. #include "display.h"
  31. #include "vncauth.h"
  32. #include "vnckeys.h"
  33. #include "ip.h"
  34. #include "sockets.h"
  35.  
  36. #include "zlib.h"
  37.  
  38.  
  39. static long ReadCompactLen (void);
  40. static Bool HandleRRE8(int rx, int ry, int rw, int rh);
  41. static Bool HandleCoRRE8(int rx, int ry, int rw, int rh);
  42. static Bool HandleHextile8(int rx, int ry, int rw, int rh);
  43. static Bool HandleRRE16(int rx, int ry, int rw, int rh);
  44. static Bool HandleCoRRE16(int rx, int ry, int rw, int rh);
  45. static Bool HandleHextile16(int rx, int ry, int rw, int rh);
  46. static Bool HandleTight16(int rx, int ry, int rw, int rh);
  47.  
  48. int rfbsock = -1;
  49. char *desktopName;
  50. rfbPixelFormat myFormat;
  51. rfbServerInitMsg si;
  52. char *serverCutText = NULL;
  53. Bool newServerCutText = False;
  54.  
  55. int endianTest = 1;
  56.  
  57. int subrect = 0;
  58.  
  59. /* note that the CoRRE encoding uses this buffer and assumes it is big enough
  60.    to hold 255 * 255 * 32 bits -> 260100 bytes.  640*480 = 307200 bytes */
  61. /* also hextile assumes it is big enough to hold 16 * 16 * 32 bits */
  62.  
  63. #define BUFFER_SIZE (640*480)
  64. static char buffer[BUFFER_SIZE];
  65.  
  66. /*
  67.  * Variables for the ``tight'' encoding implementation.
  68.  */
  69.  
  70. /* Separate buffer for compressed data. */
  71. #define ZLIB_BUFFER_SIZE 4096
  72. static char zlib_buffer[ZLIB_BUFFER_SIZE];
  73.  
  74. /* Four independent compression streams for zlib library. */
  75. static z_stream zlibStream[4];
  76. static Bool zlibStreamActive[4] = {
  77.   False, False, False, False
  78. };
  79.  
  80. /* Filter stuff. Should be initialized by filter initialization code. */
  81. static Bool cutZeros;
  82. static int rectWidth, rectColors;
  83. static char tightPalette[256*4];
  84. static CARD8 tightPrevRow[2048*3*sizeof(CARD16)];
  85.  
  86.  
  87. /*
  88.  * ConnectToRFBServer.
  89.  */
  90.  
  91. Bool ConnectToRFBServer(unsigned int host, int port) {
  92.  
  93.   rfbsock = ConnectToTcpAddr(host, port);
  94.  
  95.   if (rfbsock < 0) {
  96.     fprintf(stderr,"Unable to connect to VNC server\n");
  97.     return False;
  98.   }
  99.   if (debug)   fprintf(stderr, "Connected via socket %d\n", rfbsock);
  100.  
  101.   return SetNonBlocking(rfbsock);
  102. }
  103.  
  104.  
  105. /*
  106.  * InitialiseRFBConnection.
  107.  */
  108.  
  109. Bool
  110. InitialiseRFBConnection() {
  111.   rfbProtocolVersionMsg pv;
  112.   int major,minor;
  113.   CARD32 authScheme, reasonLen, authResult;
  114.   char *reason;
  115.   CARD8 challenge[CHALLENGESIZE];
  116.   char passwd[9];
  117.   int i;
  118.   rfbClientInitMsg ci;
  119.  
  120.   if (!ReadFromRFBServer(pv, sz_rfbProtocolVersionMsg)) {
  121.     fprintf(stderr, "Failed to read version\n");
  122.     return False;
  123.   }
  124.  
  125.   errorMessageOnReadFailure = True;
  126.  
  127.   pv[sz_rfbProtocolVersionMsg] = 0;
  128.  
  129.   if (sscanf(pv,rfbProtocolVersionFormat,&major,&minor) != 2) {
  130.     fprintf(stderr,"Not a valid VNC server\n");
  131.     return False;
  132.   }
  133.  
  134.   if (debug)
  135.     fprintf(stderr,"VNC server supports protocol version %d.%d (viewer %d.%d)\n",
  136.            major, minor, rfbProtocolMajorVersion, rfbProtocolMinorVersion);
  137.  
  138.   major = rfbProtocolMajorVersion;
  139.   minor = rfbProtocolMinorVersion;
  140.  
  141.   sprintf(pv,rfbProtocolVersionFormat,major,minor);
  142.  
  143.   if (!WriteExact(rfbsock, pv, sz_rfbProtocolVersionMsg)) return False;
  144.  
  145.   if (!ReadFromRFBServer((char *)&authScheme, 4)) return False;
  146.  
  147.   authScheme = Swap32IfLE(authScheme);
  148.  
  149.   switch (authScheme) {
  150.  
  151.   case rfbConnFailed:
  152.     if (!ReadFromRFBServer((char *)&reasonLen, 4)) return False;
  153.     reasonLen = Swap32IfLE(reasonLen);
  154.  
  155.     reason = malloc(reasonLen);
  156.  
  157.     if (!ReadFromRFBServer(reason, reasonLen)) return False;
  158.  
  159.     fprintf(stderr,"VNC connection failed: %.*s\n",(int)reasonLen, reason);
  160.     return False;
  161.  
  162.   case rfbNoAuth:
  163.     if (debug)   fprintf(stderr,"No authentication needed\n");
  164.     break;
  165.  
  166.   case rfbVncAuth:
  167.     if (!ReadFromRFBServer((char *)challenge, CHALLENGESIZE)) return False;
  168.     strcpy(passwd, password);
  169.     vncEncryptBytes(challenge, passwd);
  170.  
  171.     /* Lose the password from memory */
  172.     for (i = strlen(passwd); i >= 0; i--) {
  173.       passwd[i] = '\0';
  174.     }
  175.  
  176.     if (!WriteExact(rfbsock, (void *)challenge, CHALLENGESIZE)) return False;
  177.  
  178.     if (!ReadFromRFBServer((char *)&authResult, 4)) return False;
  179.  
  180.     authResult = Swap32IfLE(authResult);
  181.  
  182.     switch (authResult) {
  183.     case rfbVncAuthOK:
  184.       if (debug)   fprintf(stderr,"VNC authentication succeeded\n");
  185.       break;
  186.     case rfbVncAuthFailed:
  187.       fprintf(stderr,"VNC authentication failed\n");
  188.       return False;
  189.     case rfbVncAuthTooMany:
  190.       fprintf(stderr,"VNC authentication failed - too many tries\n");
  191.       return False;
  192.     default:
  193.       fprintf(stderr,"Unknown VNC authentication result: %d\n",
  194.           (int)authResult);
  195.       return False;
  196.     }
  197.     break;
  198.  
  199.   default:
  200.     fprintf(stderr,"Unknown authentication scheme from VNC server: %d\n",
  201.         (int)authScheme);
  202.     return False;
  203.   }
  204.  
  205. //  ci.shared = (appData.shareDesktop ? 1 : 0);
  206.  
  207.   if (!WriteExact(rfbsock, (char *)&ci, sz_rfbClientInitMsg)) return False;
  208.  
  209.   if (!ReadFromRFBServer((char *)&si, sz_rfbServerInitMsg)) return False;
  210.  
  211.   si.framebufferWidth = Swap16IfLE(si.framebufferWidth);
  212.   si.framebufferHeight = Swap16IfLE(si.framebufferHeight);
  213.   si.format.redMax = Swap16IfLE(si.format.redMax);
  214.   si.format.greenMax = Swap16IfLE(si.format.greenMax);
  215.   si.format.blueMax = Swap16IfLE(si.format.blueMax);
  216.   si.nameLength = Swap32IfLE(si.nameLength);
  217.  
  218.   if (debug)
  219.     fprintf(stderr,"Desktop size = %d x %d\n", si.framebufferWidth, si.framebufferHeight);
  220.  
  221.   desktopName = malloc(si.nameLength + 1);
  222.  
  223.   if (!ReadFromRFBServer(desktopName, si.nameLength)) return False;
  224.  
  225.   desktopName[si.nameLength] = 0;
  226.  
  227.   return True;
  228. }
  229.  
  230.  
  231. /*
  232.  * SetFormatAndEncodings.
  233.  */
  234.  
  235. Bool SetFormatAndEncodings() {
  236.   rfbSetPixelFormatMsg spf;
  237.   char buf[sz_rfbSetEncodingsMsg + MAX_ENCODINGS * 4];
  238.   rfbSetEncodingsMsg *se;
  239.   CARD32 *encs;
  240.   int len = 0;
  241.  
  242.   se = (rfbSetEncodingsMsg *)buf;
  243.   encs = (CARD32 *)(buf+sz_rfbSetEncodingsMsg);
  244.  
  245.   if (bpp == 16) {
  246.     myFormat.bitsPerPixel = 16;
  247.     myFormat.depth = 15;
  248.     myFormat.trueColour = 1;
  249.     myFormat.bigEndian = 0;
  250.     myFormat.redShift = 0;
  251.     myFormat.greenShift = 5;
  252.     myFormat.blueShift = 10;
  253.     myFormat.redMax = 31;
  254.     myFormat.greenMax = 31;
  255.     myFormat.blueMax = 31;
  256. /*
  257.   myFormat.bitsPerPixel = 16;
  258.   myFormat.depth = 16;
  259.   myFormat.trueColour = 1;
  260.   myFormat.bigEndian = 0;
  261.   myFormat.redShift = 11;
  262.   myFormat.greenShift = 5;
  263.   myFormat.blueShift = 0;
  264.   myFormat.redMax = 31;
  265.   myFormat.greenMax = 63;
  266.   myFormat.blueMax = 31;
  267. */
  268.   } else {
  269.     myFormat.bitsPerPixel = 8;
  270.     myFormat.depth = 8;
  271.     myFormat.trueColour = 0;
  272.     myFormat.bigEndian = 0;
  273.     myFormat.redShift = 0;
  274.     myFormat.greenShift = 3;
  275.     myFormat.blueShift = 6;
  276.     myFormat.redMax = 7;
  277.     myFormat.greenMax = 7;
  278.     myFormat.blueMax = 3;
  279.   }
  280.   spf.type = rfbSetPixelFormat;
  281.   spf.pad1 = spf.pad2 = 0;
  282.   memcpy(&spf.format, &myFormat, sizeof(rfbPixelFormat));
  283.   spf.format.redMax = Swap16IfLE(spf.format.redMax);
  284.   spf.format.greenMax = Swap16IfLE(spf.format.greenMax);
  285.   spf.format.blueMax = Swap16IfLE(spf.format.blueMax);
  286.  
  287.   if (!WriteExact(rfbsock, (char *)&spf, sz_rfbSetPixelFormatMsg))
  288.     return False;
  289.  
  290.   se->type = rfbSetEncodings;
  291.   se->nEncodings = 0;
  292.  
  293.   encs[se->nEncodings++] = Swap32IfLE(rfbEncodingCopyRect);
  294.   if (supporttight) {
  295.     // if 'tight' is supported, give it high priority
  296.     encs[se->nEncodings++] = Swap32IfLE(rfbEncodingTight);
  297.     fprintf(stderr, "Tight requested\n");
  298.   }
  299.   // hextile is usually the highest priority
  300.   encs[se->nEncodings++] = Swap32IfLE(rfbEncodingHextile);
  301.   // coRRE and RRE are old, outdated encodings, so low priority
  302.   encs[se->nEncodings++] = Swap32IfLE(rfbEncodingCoRRE);
  303.   encs[se->nEncodings++] = Swap32IfLE(rfbEncodingRRE);
  304.   // not so much encodings as encoding-controls:
  305.   if (checkclientbitmap)
  306.     encs[se->nEncodings++] = Swap32IfLE(rfbEncodingCheckClientBitmap);
  307.   if ((myFormat.bitsPerPixel == 16) && (dither8))
  308.     encs[se->nEncodings++] = Swap32IfLE(rfbEncodingHextileDither8);
  309. // XCursor not implemented - doesn't work well with hardware-pointer
  310. //  encs[se->nEncodings++] = Swap32IfLE(rfbEncodingXCursor);
  311.  
  312.   len = sz_rfbSetEncodingsMsg + se->nEncodings * 4;
  313.  
  314.   se->pad = 0;
  315.   se->nEncodings = Swap16IfLE(se->nEncodings);
  316.  
  317.   if (!WriteExact(rfbsock, buf, len)) return False;
  318.  
  319.   return True;
  320. }
  321.  
  322.  
  323. /*
  324.  * SendIncrementalFramebufferUpdateRequest.
  325.  */
  326.  
  327. Bool
  328. SendIncrementalFramebufferUpdateRequest() {
  329.   return SendFramebufferUpdateRequest(0, 0, si.framebufferWidth,
  330.                       si.framebufferHeight, True);
  331. }
  332.  
  333.  
  334. /*
  335.  * SendFramebufferUpdateRequest.
  336.  */
  337.  
  338. Bool
  339. SendFramebufferUpdateRequest(int x, int y, int w, int h, Bool incremental) {
  340.   rfbFramebufferUpdateRequestMsg fur;
  341.  
  342.   fur.type = rfbFramebufferUpdateRequest;
  343.   fur.incremental = incremental ? 1 : 0;
  344.   fur.x = Swap16IfLE(x);
  345.   fur.y = Swap16IfLE(y);
  346.   fur.w = Swap16IfLE(w);
  347.   fur.h = Swap16IfLE(h);
  348.  
  349.   if (!WriteExact(rfbsock, (char *)&fur, sz_rfbFramebufferUpdateRequestMsg)) {
  350.     fprintf(stderr, "Failed to send buffer update request\n");
  351.     return False;
  352.   }
  353.  
  354.   return True;
  355. }
  356.  
  357.  
  358. /*
  359.  * SendPointerEvent.
  360.  */
  361.  
  362. Bool
  363. SendPointerEvent(int x, int y, int buttonMask) {
  364.   rfbPointerEventMsg pe;
  365.  
  366.   pe.type = rfbPointerEvent;
  367.   pe.buttonMask = buttonMask;
  368.   if (x < 0) x = 0;
  369.   if (y < 0) y = 0;
  370.   pe.x = Swap16IfLE(x);
  371.   pe.y = Swap16IfLE(y);
  372.   return WriteExact(rfbsock, (char *)&pe, sz_rfbPointerEventMsg);
  373. }
  374.  
  375.  
  376. /*
  377.  * SendKeyEvent.
  378.  */
  379.  
  380. Bool
  381. SendKeyEvent(CARD32 key, Bool down) {
  382.   rfbKeyEventMsg ke;
  383.  
  384.   // HBP - it looks as if it is necessary to send a UpdateRequest
  385.   // before a TAB, otherwise the server seems to get stuck
  386.   if (key == VNCKEY_TAB)
  387.     if (SendIncrementalFramebufferUpdateRequest() == False)
  388.       return False;
  389.  
  390.   ke.type = rfbKeyEvent;
  391.   ke.down = down ? 1 : 0;
  392.   ke.key = Swap32IfLE(key);
  393.   return WriteExact(rfbsock, (char *)&ke, sz_rfbKeyEventMsg);
  394. }
  395.  
  396.  
  397. /*
  398.  * SendClientCutText.
  399.  */
  400.  
  401. Bool
  402. SendClientCutText(char *str, int len) {
  403.   rfbClientCutTextMsg cct;
  404.  
  405.   if (serverCutText)
  406.     free(serverCutText);
  407.   serverCutText = NULL;
  408.  
  409.   cct.type = rfbClientCutText;
  410.   cct.length = Swap32IfLE(len);
  411.   return  (WriteExact(rfbsock, (char *)&cct, sz_rfbClientCutTextMsg) &&
  412.        WriteExact(rfbsock, str, len));
  413. }
  414.  
  415. /*
  416.  * CloseConnection
  417.  */
  418. void CloseConnection() {
  419.   CloseSocket(rfbsock);
  420. }
  421.  
  422. /*
  423.  * HandleRFBServerMessage.
  424.  */
  425.  
  426. Bool
  427. HandleRFBServerMessage() {
  428.   rfbServerToClientMsg msg;
  429.  
  430.   if (buffered == 0 && ip_ready(rfbsock) < 1)
  431.     return True;
  432.   if (!ReadFromRFBServer((char *)&msg, 1))
  433.     return False;
  434.  
  435.   switch (msg.type) {
  436.   case rfbSetColourMapEntries:
  437.   {
  438.     int i;
  439.     CARD16 rgb[3];
  440.  
  441.     if (!ReadFromRFBServer(((char *)&msg) + 1,
  442.                sz_rfbSetColourMapEntriesMsg - 1))
  443.       return False;
  444.  
  445.     msg.scme.firstColour = Swap16IfLE(msg.scme.firstColour);
  446.     msg.scme.nColours = Swap16IfLE(msg.scme.nColours);
  447.  
  448.     for (i = 0; i < msg.scme.nColours; i++) {
  449.       if (!ReadFromRFBServer((char *)rgb, 6))
  450.     return False;
  451.     }
  452.  
  453.     break;
  454.   }
  455.  
  456.   case rfbFramebufferUpdate:
  457.   {
  458.     rfbFramebufferUpdateRectHeader rect;
  459.     int linesToRead;
  460.     int bytesPerLine;
  461.     int i;
  462.  
  463.     if (!ReadFromRFBServer(((char *)&msg.fu) + 1,
  464.                sz_rfbFramebufferUpdateMsg - 1))
  465.       return False;
  466.  
  467.     msg.fu.nRects = Swap16IfLE(msg.fu.nRects);
  468.     for (i = 0; i < msg.fu.nRects; i++) {
  469.       if (!ReadFromRFBServer((char *)&rect, sz_rfbFramebufferUpdateRectHeader))
  470.     return False;
  471.  
  472.       rect.r.x = Swap16IfLE(rect.r.x);
  473.       rect.r.y = Swap16IfLE(rect.r.y);
  474.       rect.r.w = Swap16IfLE(rect.r.w);
  475.       rect.r.h = Swap16IfLE(rect.r.h);
  476.       rect.encoding = Swap32IfLE(rect.encoding);
  477.  
  478.       if (rect.encoding == rfbEncodingXCursor) {
  479.     if (!HandleXCursor(rect.r.x, rect.r.y, rect.r.w, rect.r.h)) {
  480.       return False;
  481.     }
  482.     continue;
  483.       }
  484.  
  485.       if ((rect.r.x + rect.r.w > si.framebufferWidth) ||
  486.       (rect.r.y + rect.r.h > si.framebufferHeight))    {
  487.       fprintf(stderr,"Rect too large: %dx%d at (%d, %d)\n",
  488.           rect.r.w, rect.r.h, rect.r.x, rect.r.y);
  489.       return False;
  490.     }
  491.  
  492.       if ((rect.r.h * rect.r.w) == 0) {
  493.     fprintf(stderr,"Zero size rect - ignoring\n");
  494.     continue;
  495.       }
  496.  
  497.       if (rect.encoding != rfbEncodingCheckClientBitmap &&
  498.           rect.encoding != rfbEncodingCopyRect)
  499.         display_add_rectangle(rect.r.x, rect.r.y, rect.r.w, rect.r.h);
  500.  
  501.       switch (rect.encoding) {
  502.  
  503.       case rfbEncodingRaw:
  504.     bytesPerLine = rect.r.w * bpp / 8;
  505.     linesToRead = BUFFER_SIZE / bytesPerLine;
  506.  
  507.     while (rect.r.h > 0) {
  508.       if (linesToRead > rect.r.h)
  509.         linesToRead = rect.r.h;
  510.       if (linesToRead * bytesPerLine > 36*1024)
  511.         linesToRead = 36*1024/bytesPerLine;
  512.  
  513.       if (!ReadFromRFBServer(buffer,bytesPerLine * linesToRead))
  514.         return False;
  515.  
  516.       display_raw(rect.r.x, rect.r.y, rect.r.w, linesToRead, buffer, 0);
  517.  
  518.       rect.r.h -= linesToRead;
  519.       rect.r.y += linesToRead;
  520.  
  521.     }
  522.     break;
  523.  
  524.       case rfbEncodingCopyRect:
  525.       {
  526.     rfbCopyRect cr;
  527.  
  528.     if (!ReadFromRFBServer((char *)&cr, sz_rfbCopyRect))
  529.       return False;
  530.  
  531.     cr.srcX = Swap16IfLE(cr.srcX);
  532.     cr.srcY = Swap16IfLE(cr.srcY);
  533.  
  534.         if (fast_copy_ok())
  535.       BlockCopy(rect.r.x, rect.r.y, rect.r.w, rect.r.h, cr.srcX, cr.srcY);
  536.     else
  537.       display_add_rectangle(rect.r.x, rect.r.y, rect.r.w, rect.r.h);
  538.  
  539.         display_copy(rect.r.x, rect.r.y, rect.r.w, rect.r.h, cr.srcX, cr.srcY);
  540.     break;
  541.       }
  542.  
  543.       case rfbEncodingCheckClientBitmap:
  544.         // no data
  545.         break;
  546.  
  547.       case rfbEncodingRRE:
  548.         if (bpp == 8) {
  549.       if (!HandleRRE8(rect.r.x,rect.r.y,rect.r.w,rect.r.h))     return False;
  550.     } else {
  551.           if (!HandleRRE16(rect.r.x,rect.r.y,rect.r.w,rect.r.h))     return False;
  552.     }
  553.     break;
  554.  
  555.       case rfbEncodingCoRRE:
  556.         if (bpp == 8) {
  557.           if (!HandleCoRRE8(rect.r.x,rect.r.y,rect.r.w,rect.r.h))   return False;
  558.         } else {
  559.           if (!HandleCoRRE16(rect.r.x,rect.r.y,rect.r.w,rect.r.h))   return False;
  560.         }
  561.         break;
  562.  
  563.       case rfbEncodingHextile:
  564.         if (bpp == 8) {
  565.           if (!HandleHextile8(rect.r.x,rect.r.y,rect.r.w,rect.r.h))   return False;
  566.         } else {
  567.           if (!HandleHextile16(rect.r.x,rect.r.y,rect.r.w,rect.r.h))   return False;
  568.         }
  569.         break;
  570.  
  571.       case rfbEncodingTight:
  572.         if (bpp == 8) {
  573.         } else {
  574.           if (!HandleTight16(rect.r.x,rect.r.y,rect.r.w,rect.r.h))    return False;
  575.         }
  576.         break;
  577.  
  578.       default:
  579.     fprintf(stderr,"Unknown rect encoding %d\n",
  580.         (int)rect.encoding);
  581.     return False;
  582.       }
  583.     }
  584.  
  585.     if (!SendIncrementalFramebufferUpdateRequest())   return False;
  586.  
  587.     break;
  588.   }
  589.  
  590.   case rfbBell:
  591.     xos_bell();
  592.     break;
  593.  
  594.   case rfbServerCutText:
  595.   {
  596.     if (!ReadFromRFBServer(((char *)&msg) + 1,
  597.                sz_rfbServerCutTextMsg - 1))
  598.       return False;
  599.     msg.sct.length = Swap32IfLE(msg.sct.length);
  600.  
  601.     if (serverCutText)
  602.       free(serverCutText);
  603.  
  604.     serverCutText = malloc(msg.sct.length+1);
  605.  
  606.     if (!ReadFromRFBServer(serverCutText, msg.sct.length))
  607.       return False;
  608.  
  609.     serverCutText[msg.sct.length] = 0;
  610.  
  611.     newServerCutText = True;
  612.  
  613.     // HBP - it seems it is necessary to send an UpdateRequest
  614.     // after a cut text has been received, otherwise the server
  615.     // gets stuck
  616.     if (!SendIncrementalFramebufferUpdateRequest())   return False;
  617.  
  618.     break;
  619.   }
  620.  
  621.   default:
  622.     fprintf(stderr,"Unknown message type %d from VNC server\n",msg.type);
  623.     return False;
  624.   }
  625.  
  626.   return True;
  627. }
  628.  
  629.  
  630. //#define GET_PIXEL16(pix, ptr) (((CARD8*)&(pix))[0] = *(ptr)++, \
  631. //                   ((CARD8*)&(pix))[1] = *(ptr)++)
  632.  
  633. #define BPP 16
  634. #include "rre16.c"
  635. #include "corre16.c"
  636. #include "hextile16.c"
  637. #include "tight16.c"
  638. #undef BPP
  639.  
  640. #define BPP 8
  641. #include "rre8.c"
  642. #include "corre8.c"
  643. #include "hextile8.c"
  644.  
  645.  
  646. static long ReadCompactLen (void)
  647. {
  648.   long len;
  649.   CARD8 b;
  650.  
  651.   if (!ReadFromRFBServer((char *)&b, 1))
  652.     return -1;
  653.   len = (long)b & 0x7F;
  654.   if (b & 0x80) {
  655.     if (!ReadFromRFBServer((char *)&b, 1))
  656.       return -1;
  657.     len |= ((long)b & 0x7F) << 7;
  658.     if (b & 0x80) {
  659.       if (!ReadFromRFBServer((char *)&b, 1))
  660.         return -1;
  661.       len |= ((long)b & 0xFF) << 14;
  662.     }
  663.   }
  664.   return len;
  665. }
  666.